package com.ct.ecommerce.authorization.service;

import com.ct.ecommerce.api.uc.client.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author changtong
 * @since 2021/5/31
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @DubboReference
    private UserService userService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        /**
         * 去request里面拿值,如果需要
         *  ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         *  HttpServletRequest request = requestAttributes.getRequest();
         */

        return userService.findUserByName(username);
    }
}
